<%-- 
    Document   : edit_alokasi
    Created on : Jul 31, 2012, 3:01:19 PM
    Author     : MiChi
--%>

<%@page import="additional.Help"%>
<%@page import="dao.AlokasiDAOImpl"%>
<%@page import="entity.Alokasi"%>
<%@page contentType="text/html" pageEncoding="UTF-8"%>
<jsp:include page="check_session.jsp" />
<!DOCTYPE html>
<html>
     <head>
        <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
        <title>edit  alokasi</title>

        <link href="../style/style.css" rel="stylesheet" type="text/css" />

        <script src="../javascript/validasi_data.js"></script>
        <script type="text/javascript">
            <%
                long id = Long.MIN_VALUE;
                String karyawan = "";
                String pekerjaan = "";                

                if (request.getParameter("id") == null) {
                    out.write("alert('ID Karyawan Kosong!'); \n");
                    out.write("location.href='view_karyawan.jsp'; \n");
                } else {
                    id = Long.parseLong(request.getParameter("id"));
                    Alokasi k = new AlokasiDAOImpl(Help.getEM()).get(id);

                    if (k != null) {
                        karyawan = k.getKaryawan().getId()+"";
                        pekerjaan = k.getPekerjaan().getId()+"";                        
                    } else {
                        out.write("alert('ID Karyawan Tidak Ditemukan!'); \n");
                        out.write("location.href='view_karyawan.jsp'; \n");
                    }
                }
            %>
        
                function cekData(form) {
                    pesan = "PERINGATAN";
                    hasil = true;

                    if(!cekText(form.txtnama)){
                        pesan += "\nNama karyawan Kosong";
                        hasil = false;
                    }
                    if(!cekText(form.txtnoidentitas)){
                        pesan += "\nNo identitas karyawan Kosong";
                        hasil = false;
                    }
                    if(!cekText(form.txtalamat)){
                        pesan += "\nalamat karyawan Kosong";
                        hasil = false;
                    }
                    if(!cekTelepon(form.txtnotelp)){
                        pesan += "\nNotelepon harus angka";
                        hasil = false;
                    }

                    if(!hasil) {
                        alert(pesan);
                    }

                    return hasil;
                }

                function resetData(file){
                    file.form.txtkaryawan.value = "<%=karyawan%>";
                    file.form.txtpekerjaan = "<%=pekerjaan%>";
                   
                }
        </script>
    </head>

    <body>
        <div id="central">
            <div id="menuatas">
                <marquee>
                    <h3> Welcome </h3>
                </marquee>
            </div>
            
            <div id="header">
                <% 
                    if(request.getSession().getAttribute("user") == null) {
                        out.write("<a href='/TR_Persistance_Alokasi_Karyawan/Logout'>LogOut</a>");
                    } else {
                        out.write("<a href='/TR_Persistance_Alokasi_Karyawan/login.jsp'>LogIn</a>");
                    }
                %> 
            </div>

            <ul id="navlist">
                <li><a id="n1" href="Home.jsp"><span>Home</span></a></li>
                <li><a id="n2" href="view_karyawan.jsp"><span>Karyawan</span></a></li>
                <li><a id="n3" href="view_pekerjaan.jsp"><span>Pekerjaan</span></a></li>
                <li><a id="n4" href="view_alokasi.jsp"><span>Alokasi Pekerjaan</span></a></li>
                <li><a id="n5" href="about.jsp"><span>About</span></a></li>
            </ul>

            <div id="content">
                <div id="rightside">
                    <h1>Edit Data Pekerjaan</h1>

                    <br />

                    <form method="post" action="/TR_Persistance_Alokasi_Karyawan/Editalokasi?id=<%=id%>" onsubmit="return cekData(this)">
                        <table>
                            <tr>
                                <td> ID Karyawan </td>
                                <td>:</td>
                                <td><input type="text" name="txtidkaryawan" id="txtidkaryawan" value="<%=karyawan%>" /></td>
                            </tr>

                            <tr>
                                <td> ID Pekerjaan </td>
                                <td>:</td>
                                <td><input type="text" name="txtidpekerjaan"  value="<%=pekerjaan%>" /></td>
                            </tr>                          
                            <tr>
                                <td colspan="3" align="right">
                                    <input type="submit" value="Edit" />
                                    &nbsp;
                                    &nbsp;
                                    <input type="button" value="Reset" onclick="resetData(this);" />
                                </td>
                            </tr>
                        </table>
                    </form>
                </div>

                <div id="footer">
                    <p>&COPY; copyright TR PERSISTENCE</p>
                </div>
            </div>
    </body>
</html>
